package com.gg.common.utils;

import com.gg.common.helper.JWTHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * 从request请求获取当前用户信息工具类
 *
 * Author：  chenjunjia
 * Date：    2022/4/21 12:54
 * WeChat：  China_JoJo_
 */
public class AuthContextUtils {

    public static Long getUserId(HttpServletRequest request) {
        //从header中获取token
        String token = request.getHeader("token");
        //在token中获取用户id
        Long userId = JWTHelper.getUserId(token);
        return userId;
    }

    public static String getUserName(HttpServletRequest request) {
        String token = request.getHeader("token");
        String userName = JWTHelper.getUserName(token);
        return userName;
    }
}
